package com.estate.service.controller;

import com.estate.bean.Activity;
import com.estate.service.service.ActivityService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Resource
    private ActivityService activityService;

    @GetMapping("/list/{page}/{size}")
    public JsonResult list(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = activityService.listByPage(page, size);
        log.info("result:{}", result);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(Activity activity) {
        log.info("新增activity:{}", activity);
        JsonResult result = activityService.saveActivity(activity);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("activityId") String activityId) {
        log.info("删除的activityId:{}", activityId);
        JsonResult result = activityService.deleteActivity(activityId);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(Activity activity) {
        log.info("修改activity:{}", activity);
        JsonResult result = activityService.updateActivity(activity);
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/list/{activityId}")
    public JsonResult list(@PathVariable("activityId") String activityId) {
        log.info("activityId", activityId);
        JsonResult result = ResultTool.success(activityService.getById(activityId));
        log.info("result:{}", result);
        return result;
    }
}
